package com.jfinal.bbsapp.common.kit;
import java.util.Random;

import com.jfinal.kit.PropKit;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.sms.v20190711.SmsClient;
import com.tencentcloudapi.sms.v20190711.models.*;;

public class SendSmsTx {
	private String SecretId = PropKit.get("SecretId");
	private String SecretKey = PropKit.get("SecretKey");
	private String SmsSdkAppid = PropKit.get("SmsSdkAppid");
	private String AccSign = PropKit.get("AccSign");
	public static void main(String [] args) {
        try{

            Credential cred = new Credential("AKIDDMHwLajeomY5LMutZ2GID3d8PP8agtgD", "PZqCJ6UZNu1g6E6kAPP9zPYpijJcfgra");

            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("sms.tencentcloudapi.com");

            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);

            SmsClient client = new SmsClient(cred, "", clientProfile);

            SendSmsRequest req = new SendSmsRequest();
            String[] phoneNumberSet1 = {"8613676960086"};
            req.setPhoneNumberSet(phoneNumberSet1);

            req.setTemplateID("731696");
            req.setSmsSdkAppid("1400431196");
            req.setSign("小鹿鲜配");
            
            String[] templateParamSet1 = {"123456", "10"};
            req.setTemplateParamSet(templateParamSet1);

            SendSmsResponse resp = client.SendSms(req);

            System.out.println(SendSmsResponse.toJsonString(resp));
        } catch (TencentCloudSDKException e) {
                System.out.println(e.toString());
        }

    }
	
	public String sendSms(String mobile, String content,String checkminute) {
         try{
        	 Credential cred = new Credential(SecretId, SecretKey);
             HttpProfile httpProfile = new HttpProfile();
             httpProfile.setEndpoint("sms.tencentcloudapi.com");

             ClientProfile clientProfile = new ClientProfile();
             clientProfile.setHttpProfile(httpProfile);
             SmsClient client = new SmsClient(cred, "", clientProfile);

             SendSmsRequest req = new SendSmsRequest();
             req.setSmsSdkAppid(SmsSdkAppid);
             req.setSign(AccSign);
             String[] phoneNumberSet1 = {"86"+mobile};
             req.setPhoneNumberSet(phoneNumberSet1);
             req.setTemplateID("731696");
             String[] templateParamSet1 = {content, checkminute};
             req.setTemplateParamSet(templateParamSet1);

             SendSmsResponse resp = client.SendSms(req);

             System.out.println(SendSmsResponse.toJsonString(resp));
         } catch (TencentCloudSDKException e) {
                 System.out.println(e.toString());
         }
		return null;
	}
	
	public int randomInt() {
		Random ne = new Random();
		int x = ne.nextInt(9000) + 1000;
		return x;
	}
}
